﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace HuiLian.Cloud.Controls
{
    public class TextButton : Button
    {
        public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(TextButton), new PropertyMetadata("", OnPropertyChanged));

        /// <summary>
        /// 按钮文字
        /// </summary>
        [Description("文字"), Category("")]
        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }

        public static readonly DependencyProperty TextForegroundProperty = DependencyProperty.Register("TextForeground", typeof(Brush),
        typeof(TextButton), new PropertyMetadata(Brushes.Black, OnPropertyChanged));

        /// <summary>
        /// 按钮字体颜色
        /// </summary>
        [Description("字体颜色"), Category("")]
        public Brush TextForeground
        {
            set { SetValue(TextForegroundProperty, value); }
            get { return (Brush)GetValue(TextForegroundProperty); }
        }

        public static readonly DependencyProperty ButtonBackgroundProperty = DependencyProperty.Register("ButtonBackground", typeof(Brush),
        typeof(TextButton), new PropertyMetadata(Brushes.White, OnPropertyChanged));

        /// <summary>
        /// 按钮背景颜色
        /// </summary>
        [Description("背景颜色"), Category("")]
        public Brush ButtonBackground
        {
            set { SetValue(ButtonBackgroundProperty, value); }
            get { return (Brush)GetValue(ButtonBackgroundProperty); }
        }

        /// <summary>
        /// 注册边框
        /// </summary>
        public static readonly DependencyProperty ButtonThicknessProperty = DependencyProperty.Register("ButtonThickness",
            typeof(Thickness), typeof(TextButton), new PropertyMetadata(new Thickness() { Bottom = 0, Left = 0, Right = 0, Top = 0 }, OnPropertyChanged));

        public Thickness ButtonThickness
        {
            set { SetValue(ButtonThicknessProperty, value); }
            get { return (Thickness)GetValue(ButtonThicknessProperty); }
        }

        /// <summary>
        /// 注册边框颜色
        /// </summary>
        public static readonly DependencyProperty BorderColorProperty = DependencyProperty.Register("BorderColor",
            typeof(Brush), typeof(TextButton), new PropertyMetadata(Brushes.White, OnPropertyChanged));

        /// <summary>
        /// 按钮字体颜色
        /// </summary>
        [Description("边框颜色"), Category("边框按钮")]
        public Brush BorderColor
        {
            set { SetValue(BorderColorProperty, value); }
            get { return (Brush)GetValue(BorderColorProperty); }
        }

        private static void OnPropertyChanged(DependencyObject dependency, DependencyPropertyChangedEventArgs args)
        {
            TextButton button = dependency as TextButton;
            if (args.Property.Name.Equals("TextForeground"))
                button.TextForeground = (Brush)args.NewValue;
            if (args.Property.Name.Equals("ButtonBackground"))
                button.ButtonBackground = (Brush)args.NewValue;
            if (args.Property.Name.Equals("ButtonThickness"))
                button.ButtonThickness = (Thickness)args.NewValue;
            if (args.Property.Name.Equals("BorderColor"))
                button.BorderColor = (Brush)args.NewValue;
            if (args.Property.Name.Equals("Text"))
                button.Text = (string)args.NewValue;
        }

    }
}
